import { resolve } from 'path'
import { defineConfig, externalizeDepsPlugin, loadEnv } from 'electron-vite'
import vue from '@vitejs/plugin-vue'

export default defineConfig(({ mode }) => {
  const { VITE_APP_ACCESS_TOKEN, VITE_APP_BASE_URL, VITE_APP_PROJECT_ID, VITE_APP_FILE_URL } =
    loadEnv(mode, process.cwd())
  return {
    main: {
      plugins: [externalizeDepsPlugin()]
    },
    preload: {
      plugins: [externalizeDepsPlugin()]
    },
    renderer: {
      define: {
        VITE_APP_BASE_URL: `'${VITE_APP_BASE_URL}'`,
        VITE_APP_ACCESS_TOKEN: `'${VITE_APP_ACCESS_TOKEN}'`,
        VITE_APP_PROJECT_ID: `'${VITE_APP_PROJECT_ID}'`,
        VITE_APP_FILE_URL: `'${VITE_APP_FILE_URL}'`
      },
      resolve: {
        alias: {
          '@renderer': resolve('src/renderer/src')
        }
      },
      plugins: [vue()],
      server: {
        host: '0.0.0.0',
        proxy: {
          [`${VITE_APP_BASE_URL}`]: {
            target: ' http://udeedcf6.natappfree.cc/',
            changeOrigin: true,
            secure: false
          }
        }
      }
    }
  }
})
